#include <iostream>
using namespace std;
#define MaxNodeNum 30
class BinaryTree{
private:
  class Node{
  public:
    int data;
    int leftindex;
    int rightindex;
  };
  Node TNode[MaxNodeNum];
  int nodenum;
  int rootindex;
public:
  BinaryTree(int _nodenum){
    nodenum=_nodenum;
    for(int i=0;i<_nodenum;i++){
      TNode[i].leftindex=-1;
      TNode[i].rightindex=-1;
      TNode[i].data=0;
    }//initialize all the tree nodes
    rootindex=0;
  }
  void BuildATree();
  void Level_order();
  int find_index(int _data);
};
int BinaryTree::find_index(int _data){
  for(int i=0;i<nodenum;i++){
    if(TNode[i].data==_data){
      return i;
    }
  }
  return -1;//not found
}
void BinaryTree::BuildATree(){
  int post_order[MaxNodeNum];
  int in_order[MaxNodeNum];
  int index;
  int _index;
  for(int i=0;i<nodenum;i++){
    cin>>post_order[i];
  }
  for(int i=0;i<nodenum;i++){
    cin>>in_order[i];
    TNode[i].data=in_order[i];
  }
  rootindex=find_index(post_order[nodenum-1]);
  for(int j=nodenum-1;j>=0;j--){
    _index=rootindex;
    index=find_index(post_order[j]);
    while(1){
      if(index==_index){//root node
        break;
      }
      else if(index>_index){//right node
        if(TNode[_index].rightindex==-1){//leaf
          TNode[_index].rightindex=index;
          break;
        }
        _index=TNode[_index].rightindex;
      }
      else{
        if(TNode[_index].leftindex==-1){
          TNode[_index].leftindex=index;
          break;
        }
        _index=TNode[_index].leftindex;
      }
    }
  }
}
void BinaryTree::Level_order(){
  Node Queue[MaxNodeNum];
  int front=0;
  int rear=0;
  int now_index=rootindex;
  Queue[front]=TNode[now_index];
  rear++;
  while(front!=rear){
    if(front==nodenum-1){
      cout<<Queue[front].data<<endl;
    }else{
      cout<<Queue[front].data<<" ";
    }
    now_index=Queue[front].leftindex;
    if(now_index!=-1){
      Queue[rear++]=TNode[now_index];
    }
    now_index=Queue[front].rightindex;
    if(now_index!=-1){
      Queue[rear++]=TNode[now_index];
    }
    front++;
  }
}
int main(){
  int _nodenum;
  cin>>_nodenum;
  BinaryTree T(_nodenum);
  T.BuildATree();
  T.Level_order();
}
